#
# pages.py - utility routines for creating html pages for the application
#
# Copyright 2008-2009 Autelic Association (http://www.autelic.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# import generic python stuff
import sys, os, string

# Google App Engine (GAE) Pyhton libraries
from google.appengine.ext.webapp import template
from google.appengine.api import users

# Import our own modules
from loggedin import profile

class Page():
   def __init__(self, page_name):
      self.page_name = page_name

      # if logged in 
      if users.get_current_user():
         # then display their e-mail
         user_email = users.get_current_user().email()
         # create a signout link
         link_url=users.create_logout_url("/")
         link_name = 'Sign out'
      else:
         # blank the email field
         user_email = ''
         # create a signin link
         link_url=users.create_login_url("/")
         link_name = 'Sign in'

      server_name =  os.environ['SERVER_NAME']

      # create the template values for the header of page
      template_values = {
        'server_name': server_name,
        'page_header': page_name,
        'user_name': user_email,
        'url': link_url,
        'sign_in_out': link_name,
        }

      path = os.path.join(os.path.dirname(__file__), 'head.html')
      self.html = template.render(path, template_values)

   ####### Add Message
   def add_message(self, message_text):
      self.html = self.html + '<div class="message"><div class="message_title">Message</div><div class="message_content">%s</div><br clear=all></div>' % message_text

   ####### Add HTML
   def add_html(self, html):
      self.html = self.html + html

   ####### Show Page
   def show(self):
      self.html = self.html + '<div class="footer"><a href="http://www.autelic.org">Autelic</a> | <a href="/about.html">About</a></div></body></html>'

      return self.html
